package com.chen.blue.converter.system;

import com.chen.blue.domain.dto.system.MenuRoleDto;
import com.chen.blue.domain.dto.system.UserRoleDto;
import com.chen.blue.domain.dto.system.update.MenuRoleDtoEdit;
import com.chen.blue.domain.dto.system.update.UserRoleDtoEdit;
import com.chen.blue.domain.model.system.MenuRoleModel;
import com.chen.blue.domain.model.system.UserRoleModel;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2024/5/9.
 */
@SuppressWarnings("all")
public abstract class MenuRoleConverter {

    private static final BeanCopier dtoToModel = BeanCopier.create(MenuRoleDto.class, MenuRoleModel.class, false);
    private static final BeanCopier dtoEditToModel = BeanCopier.create(MenuRoleDtoEdit.class, MenuRoleModel.class, false);

    /**
     * dto->model
     *
     * @param menuRoleDto
     * @return
     */
    public static MenuRoleModel dtoToModel(MenuRoleDto menuRoleDto) {

        if (Objects.isNull(menuRoleDto)) {
            return null;
        }

        MenuRoleModel menuRoleModel = new MenuRoleModel();
        dtoToModel.copy(menuRoleDto, menuRoleModel, null);
        return menuRoleModel;

    }

    /**
     * dtoList->modelList
     *
     * @param menuRoleDtoList
     * @return
     */
    public static List<MenuRoleModel> dtoListToModelList(List<MenuRoleDto> menuRoleDtoList) {

        if (menuRoleDtoList.size() == 0) {
            return null;
        }

        List<MenuRoleModel> menuRoleModelList = new ArrayList<>();
        for (MenuRoleDto menuRoleDto : menuRoleDtoList) {
            menuRoleModelList.add(dtoToModel(menuRoleDto));
        }

        return menuRoleModelList;

    }

    /**
     * editDto->model
     *
     * @param menuRoleDtoEdit
     * @return
     */
    public static MenuRoleModel dtoEditToModel(MenuRoleDtoEdit menuRoleDtoEdit) {

        if (Objects.isNull(menuRoleDtoEdit)) {
            return null;
        }

        MenuRoleModel menuRoleModel = new MenuRoleModel();
        dtoEditToModel.copy(menuRoleDtoEdit, menuRoleModel, null);
        return menuRoleModel;

    }

    /**
     * editDtoList->modelList
     *
     * @param userRoleDtoList
     * @return
     */
    public static List<MenuRoleModel> editDtoListToModelList(List<MenuRoleDtoEdit> menuRoleDtoEditList) {

        if (menuRoleDtoEditList.size() == 0) {
            return null;
        }

        List<MenuRoleModel> menuRoleModelList = new ArrayList<>();
        for (MenuRoleDtoEdit menuRoleDtoEdit : menuRoleDtoEditList) {
            menuRoleModelList.add(dtoEditToModel(menuRoleDtoEdit));
        }

        return menuRoleModelList;

    }

}
